insert overwrite table jms_dm.dm_cusc_demand_taking_network_summary_dt
select sign_early_scantime        -- 第一次签收时间
     , taking_early_scansitecode  -- 最早揽收网点
     , taking_early_scansite_name -- 最早揽收网点名称
     , taking_agent_name          --揽收网点对应的代理区code
     , taking_agent_code          --揽收网点对应的代理区名称
     , taking_fran_code           --揽收网点对应的加盟商code
     , taking_fran_name           --揽收网点对应的加盟商名称
     , taking_provider_id         --揽收网点对应的省id
     , taking_provider_desc       --揽收网点对应的省名称
     , taking_city_id             --揽收网点对应的城市id
     , taking_city_desc           --揽收网点对应的城市名称
     , sum(is_need_call_num)                         as need_call_num
     , sum(is_have_call_num)                         as have_call_num
     , sum(is_have_call_num) / sum(is_need_call_num) as call_rate
     , sum(is_gt6_seconds)                           as gt6_seconds
     , sum(is_gt6_seconds) / sum(is_need_call_num)   as gt6_seconds_rate
     , sum(max_is_performance)                           as performance_bill_num
     , sum(max_is_performance) / sum(is_need_call_num)   as performance_bill_rate
     , '{{ execution_date | cst_ds }}'               as dt
from jms_dm.dm_cusc_demand_sign_taking_waybill_detail_dt
where dt = '{{ execution_date | cst_ds }}'
and sign_early_scantime is not null
and taking_early_scansitecode is not null
group by sign_early_scantime        -- 运单号
       , taking_early_scansitecode  -- 最早揽收网点
       , taking_early_scansite_name -- 最早揽收网点名称
       , taking_agent_name          --揽收网点对应的代理区code
       , taking_agent_code          --揽收网点对应的代理区名称
       , taking_fran_code           --揽收网点对应的加盟商code
       , taking_fran_name           --揽收网点对应的加盟商名称
       , taking_provider_id         --揽收网点对应的省id
       , taking_provider_desc       --揽收网点对应的省名称
       , taking_city_id             --揽收网点对应的城市id
       , taking_city_desc           --揽收网点对应的城市名称
    DISTRIBUTE BY dt
;